import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { config } from 'dotenv'
// 手动加载 .env 文件
config()
console.log('Current NODE_ENV:', process.env.NODE_ENV);

console.log('VITE_API_URL:', process.env.NODE_ENV == "production" ? "http://124.220.165.240:8080/" : "http://localhost:8080/")
// https://vitejs.dev/config/
export default defineConfig({

  plugins: [
    vue(),
    vueJsx(),

  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    proxy: {
      '/api/': {
         target: process.env.NODE_ENV != "development" ? "http://124.220.165.240:8080/" : "http://localhost:8080/",
        // target:"http://106.14.150.251:8080/" ,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
      '/file/': {
        target: "http://124.220.165.240:3060/",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/file/, ''),
      },
    },
  },
})
